package org.redmap.controller {
	
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import org.redmap.model.*; 
	
	public class MindMapBall extends MindMapSprite {
		
		//public var id:String;
		//private var radius:Number;
		//private var color:uint;		
		public var dragging:Boolean=false;
		private var textField:TextField;

		
		public static var counter:int = -1;
		

		
		public function MindMapBall( _id:String=null ,radius:Number=30, color:uint=0xfff000 , label:String=null) {
			
		 	if (_id != null){
		 		counter = parseInt(_id);
				this._id = _id;
			}
			else {
				_id = new Number(++counter).toString();
			}
			
			if (label != null && label.length != 0) {
				this.label = label
			} else {
				label = _id;
			}

			var textFormat:TextFormat = new TextFormat();
            textFormat.align = TextFormatAlign.CENTER;

            textField = new TextField();
            textField.defaultTextFormat = textFormat;

            addChild(textField);
            
            super(_id,myWidth,myHeight,radius,color,label);
            this.geometricShape = new Ball(radius);
			
			 drawShape();
		}

		
		public override function drawShape():void {
			
			this.graphics.clear();
			
			// recenters the textfield depending on the radius
            
            textField.y = radius;
            
            textField.text = label;
            
            this.graphics.lineStyle(1.0, this.color, 1.0);
			this.graphics.beginFill(this.color, 1.0);
			if (label.length == 1 || label.length == 0){
            	this.graphics.drawCircle(radius, radius, radius);
   			} else {
   				this.graphics.drawCircle(radius, radius, label.length * 2 + 20);
				textField.width = radius * 2 + 20;
   			}
    	}
	}
}